package com.cjm.one.controller.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.goods.dto.GoodsCommentDto;
import com.cjm.one.model.goods.entity.GoodsComment;
import com.cjm.one.model.goods.entity.GoodsCommentTag;
import com.cjm.one.model.goods.vo.GoodsCommentCountVo;
import com.cjm.one.model.goods.vo.GoodsCommentTagVo;
import com.cjm.one.model.goods.vo.GoodsCommentVo;
import com.cjm.one.service.GoodsCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "商品评论", description = "商品评论管理")
@RequestMapping("/api/goods/comment")
public class GoodsCommentController {
    @Resource
    private GoodsCommentService goodsCommentService;
    @GetMapping("/list")
    @Operation(summary = "商品评论列表")
    Result<Page<GoodsCommentVo>> list(
            @RequestParam(value = "current", defaultValue = "1") Integer current,
            @RequestParam(value = "size", defaultValue = "10") Integer size,
            @RequestParam(value = "goodsId") Long goodsId,
            @RequestParam(value = "sortOrder", required = false) String sortOrder,
            @RequestParam(value = "tagIds", required = false) List<Long> tagIds) {
        return goodsCommentService.listPageByGoodsId(current, size, goodsId, sortOrder, tagIds);
    }
    @GetMapping("/getTagById")
    @Operation(summary = "根据商品id获取商品评论的标签")
    public Result<GoodsCommentCountVo> getTagById(@RequestParam("id") Long id){
        return goodsCommentService.getTagByGoodsId(id);
    }

    @GetMapping("/top3")
    @Operation(summary = "获取热门前三评论")
    public Result<List<GoodsComment>> getTopComments(@RequestParam(value = "goodsId") Long goodsId){
        return goodsCommentService.getTopComments(goodsId);
    }
    @GetMapping("/tags")
    @Operation(summary = "获取所有评论标签")
    public Result<List<GoodsCommentTag>> getTags(){
        return goodsCommentService.getTags();
    }

    @PostMapping("/save")
    @Operation(summary = "保存商品评论")
    public Result<Boolean> save(@RequestBody List<GoodsCommentDto> goodsCommentDto){
        return goodsCommentService.saveGoodsComment(goodsCommentDto);


    }

}
